package com.clothes.aweiDoExercises.config;

import com.jd.platform.hotkey.client.ClientStarter;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 京东HotKey热key发现配置
 *
 * @author <<a href="www.yclothes.top">阿伟智能面试刷题平台</a>">clothes</a>
 * @from <a href="https://yupi.icu">阿伟智能刷题平台</a>
 */
@Configuration
@ConfigurationProperties(prefix = "hotkey")
@Data
public class HotKeyConfig {
    // etcd服务地址
    private String etcdServer = "http://127.0.0.1:2379";

    // 应用名称
    private String appName = "app";

    // 本地缓存的最大数量
    private int caffeineSize = 10000;

    //批量推送key的间隔时间(尽量减少连接次数进行批处理)
    private long pushPeriod = 1000L;

    @Bean
    public void initHotkey() {
        ClientStarter.Builder builder = new ClientStarter.Builder();
        ClientStarter starter = builder.setAppName(appName)
                .setCaffeineSize(caffeineSize)
                .setPushPeriod(pushPeriod)
                .setEtcdServer(etcdServer)
                .build();
        starter.startPipeline();
    }


}
